jQuery(function($){
	
	var shopCarList = $(".shopCarList"),
	    checkAll = $('.quanxuan');
	
	//单选
	shopCarList.on("click", ".check", function(){
        $(this).parent().toggleClass("ed");
        if(shopCarList.children().length == shopCarList.children(".ed").length){
        	checkAll.addClass("ed");
        }else{
        	checkAll.removeClass("ed");
        }
        total();
    })
	
    //全选
    checkAll.click(function(){
		if($(this).hasClass("ed")){
			$(this).removeClass("ed");
       		shopCarList.children(".ed").removeClass("ed");
       	}else{
       		$(this).addClass("ed");
        	shopCarList.children(":not(.ed)").addClass("ed");
       	}
       	total();
    })
    
    function total(){
    	var num = 0;
    	shopCarList.children('.ed').find('.price').each(function(i,v){
    		var spans = $(v).find("span");
    		
    		//num += parseFloat( spans.eq(0).text() ) * parseInt( spans.eq(1).text() );
    		num +=  spans.eq(0).text() * spans.eq(1).text();
    	});
    	$(".heji .a_two").html(num);
    }
    
   
    
    $('.jiesuan').click(function(){
        location.href="confirmOrder.html";
    })
    
    
	$.ajax({
            url:"../json/shoppingCart.json",
            type:"get",
            success: function(data){
            	console.log(data)
                var str = template("shopCarTemp",{list:data});
                console.log(str)
                $('.shopCarList').html(str);
            }
        })
       
});
